package com.chuyu.cy.controller;

import com.chuyu.cy.contants.ResponseCodeEnum;
import com.chuyu.cy.contants.Result;
import com.chuyu.cy.entity.dto.LoginDTO;
import com.chuyu.cy.entity.vo.LoginVO;
import com.chuyu.cy.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 周小白
 */
@RestController
@Tag(name = "登录管理")
public class LoginController {

    @Resource
    private UserService userService;




    /**
     * 登录
     * @param loginDTO 登录信息
     * @return 登录结果
     */
    @PostMapping("/login")
    @Operation(summary = "登录")
    public Result<LoginVO> login(@RequestBody LoginDTO loginDTO){
        Result<LoginVO> result = new Result<>();

        if (loginDTO == null) {
            return result.failure(ResponseCodeEnum.NO_PARAM);
        }

        LoginVO login = userService.login(loginDTO);
        if (login == null) {
            return result.failure("用户名或密码错误");
        }

        return result.success(login);
    }
}
